<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta http-equiv="Cache-Control" content="max-age=180">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<meta http-equiv="x-dns-prefetch-control" content="on">
<title>编辑地址</title>
<link rel="stylesheet" href="../css/bootstrap.css">
<link href="css/iconfont.css" rel="stylesheet" type="text/css" />
<link href="css/basestyle.css" rel="stylesheet" type="text/css" />
<link href="css/common.css" rel="stylesheet" type="text/css" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="../css/toast.css">
<link href="../css/bootstrap.css" rel="stylesheet" type="text/css" />
</head>
<body style="background:#fff">
<div id="loadingToast" style="opacity: 1; display: block;">
        <div class="weui-mask_transparent"></div>
        <div class="weui-toast">
            <i class="weui-loading weui-icon_toast"></i>
            <p class="weui-toast__content">加载中</p>
        </div>
</div>
<div class="wx-containe">
  <div class="address_main">
    <div class="line">
      <input type="text" placeholder="收件人" id="realname" value="">
    </div>
    <div class="line">
      <input type="tel" placeholder="联系电话" id="mobile" value="">
    </div>
    <div class="line"> 
      <!-- sel-provance -->
      <select id="s_province" name="s_province">
        <option value="-1">省份</option>
      </select>
      <br>
    </div>
    <div class="line">
      <select id="s_city" name="s_city" >
        <option value="-1">地级市</option>
      </select>
      <br>
      <!-- sel --> 
    </div>
    <!-- <div class="line"> 
      sel-area
      <select id="s_county" name="s_county">
        <option value="市、县级市">市、县级市</option>
      </select>
    </div> -->
    <div class="line">
      <!-- <input type="text" placeholder="详细地址" id="address" value=""> -->
      <textarea id="address" style="width: 100%; border-bottom: 1px solid #b9b9b3;" placeholder="详细地址"></textarea>
    </div>
  </div>
</div>
<div class="ft-blank"></div>
<div class="footer-btn" style="height: 5.3rem">
  <button class="confirm-btn adres" id="addAddrBtn"  >确认</button>
</div>
<script type="text/javascript" src="js/jquery-1.10.2.js"></script>
<!-- cookie操作js -->
<script charset="utf-8" src="../js/global.js"></script>
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="js/swiper.min.js"></script>
<script charset="utf-8" src="../js/wxLoginInfo.js"></script>
<script charset="utf-8" src="../js/StringBuilder.js"></script>
<script charset="utf-8" src="../js/templeteHtml.js"></script>
<script charset="utf-8" src="../js/bootstrap.min.js"></script>
<script type="text/javascript">
		//加载省级选择菜单
		leadSelect("s_province",null);
		//级联菜单
		 $("#s_province").change(function(){
			 var changeVal=$(this).val();
			 $("#s_city").html('<option value="-1">地级市</option>');
				if(changeVal!=-1){
					leadSelect("s_city",changeVal);
				}
		})
		function leadSelect(id,code){
			 $.get("../xxmember/addressSelByCode",{code:code},function(ret){
					if(ret&&ret.code==200&&ret.data){
						var datas=ret.data;
						for(var i in datas){
							$("#"+id).append('<option value="'+datas[i].code+'">'+datas[i].name+'</option>');
							}
						}	
						$("#loadingToast").attr("style","opacity:0; display: none;");
					},'json')
				}

		 $("#addAddrBtn").click(function(){ 
			var realname=$("#realname").val();
			var mobile=$("#mobile").val();
			var s_province=$("#s_province option:selected").text();
			var s_provinceCode=$("#s_province option:selected").val();
			var s_city=$("#s_city option:selected").text();
			var s_cityCode=$("#s_city option:selected").val();
			var address=$("#address").val();
			
			 if($.trim(realname)==""){
				 floatNotify.simple("请填写收件人名字！");
				 $("#realname").focus();
				 return;
			}
			 var reg = new RegExp("^[0-9]*$");
			 if($.trim(mobile)==""||!reg.test(mobile)){
				 floatNotify.simple("联系电话不正确！");
				 $("#mobile").focus();
				 return;
			}
			 if(s_provinceCode==-1){
				 floatNotify.simple("请选择省份！");
				 $("#s_province").focus();
				 return;
			}
			 if(s_cityCode==-1){
				 floatNotify.simple("请选择城市！");
				 $("#s_city").focus();
				 return;
			}
			 if($.trim(address)==""){
				 floatNotify.simple("请填写详细地址信息！");
				 $("#address").focus();
				 return;
			}
			 floatNotify.simple("数据提交中，请稍后...");
			 loginInfo(function(userInfo){
				 $.post("../xxreceiver/addReceiver",{member:userInfo.id,area:s_cityCode,phone:mobile,consignee:realname,area_name:s_province+s_city,address:address},function(ret){
					 if(ret&&ret.code==200){
						 floatNotify.simple("添加成功！");
						 history.go(-1);
						 location.reload();
					 }else{
						 floatNotify.simple("添加失败！");
						 }
					// $("#addAddrBtn").attr("disabled",false);
				},'json')
			})
		})
</script>
</body>
</html>
